import ProTable, {ActionType} from '@ant-design/pro-table';
import { PageContainer } from '@ant-design/pro-layout';
import { Card } from 'antd';
import {bargainList } from "@/services/ant-design-pro/marketing";
import {useRef} from "react";



export default () => {
  const actionRef = useRef<ActionType>();

  const columns = [
    {
      title: '审核状态',
      dataIndex: 'time',
      valueType: 'radioButton',
      initialValue: '',
      hideInTable: true,
      colSize: '24',
      valueEnum: {
        '': '全部',
        today: '待审核',
        week: '已通过',
        yesterday: '未通过',
      }
    },
    {
      title: '搜索',
      dataIndex: '',
      hideInTable: false,
    },
    {
      dataIndex: 'us',
      title: '商品ID',
      search: false,
      align: 'center',
    },
    {
      title: '商品名称',
      dataIndex: 'title',
      align: 'center',
      copyable: true,
      ellipsis: true,
      search: false,
    },
    {
      title: '直播价',
      dataIndex: 'start',
      hideInTable: true,
      search: false,
    },
    {
      title: '原价',
      dataIndex: 'time',
      align: 'center',
      search: false,
    },
    {
      title: '库存',
      dataIndex: 'text',
      align: 'center',
      search: false,
    },
    {
      title: '审核状态',
      dataIndex: 'text',
      search: false,
      align: 'center',
    },
    {
      title: '是否显示',
      dataIndex: 'text',
      search: false,
      align: 'center',
    },
    {
      title: '操作',
      valueType: 'option',
      fixed: 'right',
      align: 'center',
      width: 200,
    },
  ];

  return (
    <PageContainer
      header={{
        breadcrumb: {},
      }}
    >
      <Card>
        <ProTable

          actionRef={actionRef}
          columns={columns}
          request={async (params={}) => {
            let {data,meta} =  await bargainList({...params})
            return{
              data,
              success:true,
              total:meta.pagination.total
            }
          }}
          editable={{
            type: 'multiple',
          }}
          rowKey="id"
          search={{
            labelWidth: 'auto',
            defaultCollapsed: false,
            collapseRender: false,
          }}
          scroll={{ x: 1300 }}
          form={{
            // 由于配置了 transform，提交的参与与定义的不同这里需要转化一下
            syncToUrl: (values, type) => {
              if (type === 'get') {
                return {
                  ...values,
                  created_at: [values.startTime, values.endTime],
                };
              }
              return values;
            },
          }}
          pagination={{
            pageSize: 5,
          }}
          dateFormatter="string"
        />
      </Card>

    </PageContainer>

  );
};
